import Vue from "vue";
import App from "./App";
import router from "./router";

// 导入全局样式
import "./assets/css/global.css";

// 导入字体图标库
import "./assets/fonts/iconfont.css";

//导入axios
import axios from "axios";

//安装element-ui组件
import ElementUI from "element-ui";
Vue.use(ElementUI);
Vue.config.productionTip = false;

//添加导航守卫
router.beforeEach((to, from, next) => {
  // to and from are both route objects
  if (to.path == "/login") return next();
  const token = sessionStorage.getItem("token");
  if (!token) return next("/login");
  next();
});
// 把 axios 挂载 到 Vue 上
// 配置 baseURL 地址
axios.defaults.baseURL = "https://www.liulongbin.top:8888/api/private/v1/";
Vue.prototype.$http = axios;

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  render: h => h(App)
});
